﻿<?xml version="1.0" encoding="utf-8"?>
<witd:WITD application="Work item type editor" version="1.0" xmlns:witd="http://schemas.microsoft.com/VisualStudio/2008/workitemtracking/typedef">
  <WORKITEMTYPE name="Code Review Request">
    <DESCRIPTION>Represents the master work item for a code review. Child work items should be created of the type Code Review Response.</DESCRIPTION>
    <FIELDS>
      <!-- ********** Core fields ******************* -->
      <FIELD name="Id" refname="System.Id" type="Integer" reportable="dimension" />
      <FIELD name="Title" refname="System.Title" type="String" reportable="dimension">
        <REQUIRED />
      </FIELD>
      <FIELD name="Assigned To" refname="System.AssignedTo" type="String" reportable="dimension" syncnamechanges="true">
        <ALLOWEXISTINGVALUE/>
        <VALIDUSER/>
      </FIELD>
      <FIELD name="Created Date" refname="System.CreatedDate" type="DateTime" reportable="dimension" />
      <FIELD name="Created By" refname="System.CreatedBy" type="String" reportable="dimension" syncnamechanges="true"/>
      <FIELD name="Changed Date" refname="System.ChangedDate" type="DateTime" reportable="dimension" />
      <FIELD name="Changed By" refname="System.ChangedBy" type="String" reportable="dimension" syncnamechanges="true"/>
      <FIELD name="Closed Date" refname="Microsoft.VSTS.Common.ClosedDate" type="DateTime" reportable="dimension"/>
      <FIELD name="Closed By" refname="Microsoft.VSTS.Common.ClosedBy" type="String" reportable="dimension" syncnamechanges="true"/>
      <FIELD name="State" refname="System.State" type="String" reportable="dimension"/>
        <FIELD name="Reason" refname="System.Reason" type="String" reportable="dimension"/>
      <FIELD name="History" refname="System.History" type="History"/>
      <FIELD name="Area Path" refname="System.AreaPath" type="TreePath" reportable="dimension"/>
      <FIELD name="Iteration Path" refname="System.IterationPath" type="TreePath" reportable="dimension"/>
      <FIELD name="Closing Comment" refname="Microsoft.VSTS.CodeReview.ClosingComment" type="String"/>
      <FIELD name="Associated Context Code" refname="Microsoft.VSTS.CodeReview.ContextCode" type="Integer">
        <WHEN field="Microsoft.VSTS.CodeReview.ContextType" value="Shelveset">
          <COPY from="value" value="1" />
        </WHEN>
        <WHEN field="Microsoft.VSTS.CodeReview.ContextType" value="Changeset">
          <COPY from="value" value="2" />
        </WHEN>
      </FIELD>
      <FIELD name="Associated Context Type" refname="Microsoft.VSTS.CodeReview.ContextType" type="String">
        <WHEN field="Microsoft.VSTS.CodeReview.ContextCode" value="1">
          <COPY from="value" value="Shelveset" />
        </WHEN>
        <WHEN field="Microsoft.VSTS.CodeReview.ContextCode" value="2">
          <COPY from="value" value="Changeset" />
        </WHEN>
        <ALLOWEDVALUES>
          <LISTITEM value="Shelveset" />
          <LISTITEM value="Changeset" />
        </ALLOWEDVALUES>
        <DEFAULT from="value" value="Shelveset" />
      </FIELD>
      <FIELD name="Associated Context" refname="Microsoft.VSTS.CodeReview.Context" type="String">
        <REQUIRED />
      </FIELD>
      <FIELD name="Associated Context Owner" refname="Microsoft.VSTS.CodeReview.ContextOwner" type="String"/>

      <FIELD name="Closed Status Code" refname="Microsoft.VSTS.CodeReview.ClosedStatusCode" type="Integer">
        <WHEN field="Microsoft.VSTS.CodeReview.ClosedStatus" value="">
          <COPY from="value" value="0" />
        </WHEN>
        <WHEN field="Microsoft.VSTS.CodeReview.ClosedStatus" value="Abandoned">
          <COPY from="value" value="1" />
        </WHEN>
        <WHEN field="Microsoft.VSTS.CodeReview.ClosedStatus" value="Checked-in">
          <COPY from="value" value="2" />
        </WHEN>
        <WHEN field="Microsoft.VSTS.CodeReview.ClosedStatus" value="Completed">
          <COPY from="value" value="3" />
        </WHEN>
        <ALLOWEDVALUES expanditems="true">
          <LISTITEM value="0"/>
          <LISTITEM value="1"/>
          <LISTITEM value="2"/>
          <LISTITEM value="3"/>
        </ALLOWEDVALUES>
        <DEFAULT from="value" value="0" />
      </FIELD>
      <FIELD name="Closed Status" refname="Microsoft.VSTS.CodeReview.ClosedStatus" type="String" reportable="dimension">
        <WHEN field="Microsoft.VSTS.CodeReview.ClosedStatusCode" value="0">
          <COPY from="value" value="" />
        </WHEN>
        <WHEN field="Microsoft.VSTS.CodeReview.ClosedStatusCode" value="1">
          <COPY from="value" value="Abandoned" />
        </WHEN>
        <WHEN field="Microsoft.VSTS.CodeReview.ClosedStatusCode" value="2">
          <COPY from="value" value="Checked-in" />
        </WHEN>
        <WHEN field="Microsoft.VSTS.CodeReview.ClosedStatusCode" value="3">
          <COPY from="value" value="Completed" />
        </WHEN>
        <ALLOWEDVALUES>
          <LISTITEM value="Abandoned" />
          <LISTITEM value="Checked-in" />
          <LISTITEM value="Completed" />
        </ALLOWEDVALUES>
      </FIELD>
      <!-- **************** Team Build Integration Fields **************  -->
      <FIELD name="Integration Build" refname="Microsoft.VSTS.Build.IntegrationBuild" type="String" reportable="dimension">
        <SUGGESTEDVALUES>
          <LISTITEM value="&lt;None&gt;" />
        </SUGGESTEDVALUES>
      </FIELD>
      <!-- **************** Mirror field to determine the current state in code -->
      <FIELD name="State Code" refname="Microsoft.VSTS.Common.StateCode" type="Integer">
        <WHEN field="System.State" value="Requested">
          <COPY from="value" value="0" />
        </WHEN>
        <WHEN field="System.State" value="Closed">
          <COPY from="value" value="1" />
        </WHEN>
        <ALLOWEDVALUES expanditems="true">
          <LISTITEM value="0"/>
          <LISTITEM value="1"/>
        </ALLOWEDVALUES>
        <DEFAULT from="value" value="0" />
      </FIELD>

    </FIELDS>

    <!-- *************** Workflow ****************   -->
    <WORKFLOW>
      <STATES>
        <STATE value="Requested">
          <FIELDS>
            <FIELD refname="Microsoft.VSTS.Common.ClosedDate">
              <EMPTY />
            </FIELD>
            <FIELD refname="Microsoft.VSTS.Common.ClosedBy">
              <EMPTY />
            </FIELD>
            <FIELD refname="Microsoft.VSTS.CodeReview.ClosingComment">
              <EMPTY />
            </FIELD>
            <FIELD refname="Microsoft.VSTS.CodeReview.ClosedStatus">
              <EMPTY />
            </FIELD>
            <FIELD refname="Microsoft.VSTS.CodeReview.ClosedStatusCode">
              <READONLY />
            </FIELD>
          </FIELDS>
        </STATE>

        <STATE value="Closed">
          <FIELDS>
            <FIELD refname="Microsoft.VSTS.Common.ClosedBy">
              <REQUIRED />
            </FIELD>
            <FIELD refname="Microsoft.VSTS.Common.ClosedDate">
              <REQUIRED />
            </FIELD>
            <FIELD refname="Microsoft.VSTS.CodeReview.ClosedStatus">
              <REQUIRED />
            </FIELD>
          </FIELDS>
        </STATE>
      </STATES>

      <TRANSITIONS>
        <TRANSITION from="" to="Requested">
          <REASONS>
            <DEFAULTREASON value="New" />
          </REASONS>
          <FIELDS>
            <FIELD refname="System.AssignedTo">
              <COPY from="currentuser" />
              <VALIDUSER />
            </FIELD>
          </FIELDS>
        </TRANSITION>

        <TRANSITION from="Requested" to="Closed">
          <ACTIONS>
            <ACTION value="Microsoft.VSTS.Actions.Checkin" />
            <ACTION value="Microsoft.VSTS.CodeReview.Abandon" />
          </ACTIONS>
          <REASONS>
            <DEFAULTREASON value="Closed" />
          </REASONS>
          <FIELDS>
            <!-- Set the closing date -->
            <FIELD refname="Microsoft.VSTS.Common.ClosedDate">
              <SERVERDEFAULT from="clock" />
            </FIELD>
            <!-- Set the closing person -->
            <FIELD refname="Microsoft.VSTS.Common.ClosedBy">
              <COPY from="currentuser" />
              <VALIDUSER />
            </FIELD>
            <!-- Unassign the workitem -->
            <FIELD refname="System.AssignedTo">
              <COPY from="value" value="" />
            </FIELD>
            <FIELD refname="Microsoft.VSTS.CodeReview.ClosedStatusCode">
              <COPY from="value" value="2" />
            </FIELD>
            <FIELD refname="Microsoft.VSTS.CodeReview.ClosedStatus">
              <COPY from="value" value="Checked-in" />
            </FIELD>
          </FIELDS>
        </TRANSITION>
      </TRANSITIONS>
    </WORKFLOW>

    <FORM>
      <Layout HideControlBorders="true">
        <Group>
          <Column PercentWidth="100">
            <Control ReadOnly="True" Type="FieldControl" FieldName="System.Title" ControlFontSize="large" EmptyText="&lt;Enter title here&gt;" />
          </Column>
        </Group>
        <Group Margin="(5,0,0,0)">
          <Column PercentWidth="50">
            <Group Label="Information">
              <Column PercentWidth="100">
                <Control ReadOnly="True" Type="FieldControl" FieldName="System.AssignedTo" Label="Assi&amp;gned To" LabelPosition="Left" EmptyText="&lt;No one&gt;" />
                <Control ReadOnly="True" Type="FieldControl" FieldName="Microsoft.VSTS.CodeReview.ContextType" Label="Associated Context Type" LabelPosition="Left" />
                <Control ReadOnly="True" Type="FieldControl" FieldName="Microsoft.VSTS.CodeReview.Context" Label="Associated Context" LabelPosition="Left" />
                <Control ReadOnly="True" Type="FieldControl" FieldName="Microsoft.VSTS.CodeReview.ContextOwner" Label="Associated Context Owner" LabelPosition="Left" />
              </Column>
            </Group>
          </Column>
          <Column PercentWidth="50">
            <Group Label="Classification">
              <Column PercentWidth="100">
                <Control ReadOnly="True" Type="WorkItemClassificationControl" FieldName="System.AreaPath" Label="&amp;Area" LabelPosition="Left" />
                <Control ReadOnly="True" Type="WorkItemClassificationControl" FieldName="System.IterationPath" Label="Ite&amp;ration" LabelPosition="Left" />
              </Column>
            </Group>
          </Column>
        </Group>
        <Group Margin="(5,0,0,0)">
          <Column PercentWidth="50">
            <Group Label="Status">
              <Column PercentWidth="100">
                <Control ReadOnly="True" Type="FieldControl" FieldName="System.State" Label="Stat&amp;e" LabelPosition="Left" />
                <Control ReadOnly="True" Type="FieldControl" FieldName="System.Reason" Label="Reason" LabelPosition="Left" />
              </Column>
            </Group>
          </Column>
          <Column PercentWidth="50">
            <Group Label="System Info">
              <Column PercentWidth="100">
                <Control ReadOnly="True" Type="FieldControl" FieldName="System.CreatedBy" Label="Created By" LabelPosition="Left" />
                <Control ReadOnly="True" Type="FieldControl" FieldName="System.CreatedDate" Label="Created Date" LabelPosition="Left" />

                <Control ReadOnly="True" Type="FieldControl" FieldName="System.ChangedBy" Label="Updated By" LabelPosition="Left" />
                <Control ReadOnly="True" Type="FieldControl" FieldName="System.ChangedDate" Label="Updated Date" LabelPosition="Left" />

                <Control ReadOnly="True" Type="FieldControl" FieldName="Microsoft.VSTS.Common.ClosedBy" Label="Closed By" LabelPosition="Left" />
                <Control ReadOnly="True" Type="FieldControl" FieldName="Microsoft.VSTS.Common.ClosedDate" Label="Closed Date" LabelPosition="Left" />
                <Control ReadOnly="True" Type="FieldControl" FieldName="Microsoft.VSTS.CodeReview.ClosedStatus" Label="Closed Status" LabelPosition="Left" />
                <Control ReadOnly="True" Type="FieldControl" FieldName="Microsoft.VSTS.CodeReview.ClosingComment" Label="Closing Comment" LabelPosition="Left" />
              </Column>
            </Group>
          </Column>
        </Group>
        <TabGroup>
          <Tab Label="Details">
            <Group>
              <Column PercentWidth="50">
                <Control ReadOnly="True" Type="HtmlFieldControl" FieldName="System.Description" Label="Description" LabelPosition="Top" Dock="Fill" />
              </Column>
              <Column PercentWidth="50">
                <Control ReadOnly="True" Type="WorkItemLogControl" FieldName="System.History" Label="Histor&amp;y" LabelPosition="Top" Dock="Fill" />
              </Column>
            </Group>
          </Tab>
          <Tab Label="Links" >
            <Control ReadOnly="True" Type="LinksControl" Name="ChildLinks" Label="Requests" LabelPosition="Top">
              <LinksControlOptions>
                <WorkItemLinkFilters FilterType="include">
                  <Filter LinkType="System.LinkTypes.Hierarchy" />
                </WorkItemLinkFilters>
                <WorkItemTypeFilters FilterType="include">
                  <Filter WorkItemType="Code Review Response" />
                </WorkItemTypeFilters>
                <ExternalLinkFilters FilterType="excludeAll"/>
                <LinkColumns>
                  <LinkColumn RefName="System.ID" />
                  <LinkColumn RefName="System.WorkItemType" />
                  <LinkColumn RefName="System.AssignedTo" />
                  <LinkColumn RefName="System.State" />
                  <LinkColumn RefName="Microsoft.VSTS.Common.ClosedBy" />
                  <LinkColumn RefName="Microsoft.VSTS.CodeReview.ClosedStatus" />
                  <LinkColumn RefName="Microsoft.VSTS.Common.ClosedDate" />
                  <LinkColumn LinkAttribute="System.Links.Comment" />
                </LinkColumns>
              </LinksControlOptions>
            </Control>
          </Tab>
        </TabGroup>
      </Layout>
    </FORM>
  </WORKITEMTYPE>
</witd:WITD>
